<template>
  <div class="">
    <div class="page-filter mb10 fl">
      <el-form ref="filter" :model="filter" label-width="0">
        <el-form-item class="mr10 mb5 fl">
          <el-input v-model="filter.name" placeholder="姓名" size="small" clearable />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl" style="width: 300px">
          <el-button size="small" @click="app.reset('filter')">清 空</el-button>
          <el-button type="primary" size="small" @click="getList">查 询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table v-loading="app.loading" class="search-table" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="序号" align="center" width="56px">
        <template slot-scope="{$index}">
          {{ $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="姓名" width="120px" prop="nickname" />
      <el-table-column label="性别" align="center" width="80px" :formatter="formatter"/>
      <el-table-column label="出生日期" align="center" width="110px" prop="birthday" />
      <el-table-column label="身份证号" align="center" width="190px" prop="card" />
      <el-table-column label="户籍" width="220px" prop="hometown" />
      <el-table-column label="地址" width="220px" prop="lived" />
      <el-table-column label="婚姻状态" align="center" width="80px" :formatter="formatterMarriage"/>
      <el-table-column label="生育状态" align="center" width="80px" :formatter="formatterBirth"/>
      <el-table-column label="工作经验" width="260px" prop="work" />
      <el-table-column label="自我评价" width="260px" prop="appraise" />
      <el-table-column label="备注" min-width="260px" prop="remark" />
      <el-table-column label="操作" align="center" width="90px" fixed="right">
        <template slot-scope="{row}">
          <el-dropdown>
            <el-button type="primary" size="mini">
              操作<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="handleEdit(row)">编 辑</el-dropdown-item>
              <el-dropdown-item @click.native="contacts(row)">联系方式</el-dropdown-item>
              <el-dropdown-item @click.native="educations(row)">教育背景</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="filter.pageAll>0" :total="filter.pageAll" :page.sync="filter.pageCurrent" :limit.sync="filter.pageNumber" @pagination="getList" />
    <Dialog ref="dialog" :get-data="getList" :info="dialog" />
    <Contacts ref="contacts" :get-data="getList" :info="dialog" />
    <Educations ref="educations" :get-data="getList" :info="dialog" />
  </div>
</template>

<script>
import { resumes, delResume } from '@/api/staff'
import Pagination from '@/components/Pagination'
import Dialog from './components/resume-dialog'
import Contacts from './components/contacts-dialog'
import Educations from './components/educations-dialog'

export default {
  name: '',
  components: { Pagination, Dialog, Contacts, Educations },
  inject: ['app'],
  data() {
    return {
      list: [{name: '名称'}],
      dialog: {
        edit: {},
        title: '',
        type: ''
      },
      filter: {
        pageNumber: 10,
        pageCurrent: 1,
        pageAll: 1
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList(e) {
      this.app.loading = true
      resumes({
        ...this.filter,
        ...e
      }).then(response => {
        this.list = response.list
        this.filter = response.filter
        this.app.removeLoding()
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    formatterMarriage(e) {
      let s = '-'
      switch (e.marriage) {
        case 0:
          s = '未婚'
          break;
        case 1:
          s = '已婚'
          break;
        default:
          break;
      }
      return s
    },
    formatterBirth(e) {
      let s = '-'
      switch (e.birth) {
        case 0:
          s = '未育'
          break;
        case 1:
          s = '已育'
          break;
        default:
          break;
      }
      return s
    },
    formatter(e) {
      let sex = '-'
      switch (e.sex) {
        case 1:
          sex = '男'
          break;
        case 2:
          sex = '女'
          break;
        default:
          break;
      }
      return sex
    },
    contacts(e) {
      this.dialog.title = '联系方式'
      this.app.dialogParam(this.dialog.edit, ['id'], e)
      this.$refs['contacts'].visible = true
    },
    educations(e) {
      this.dialog.title = '教育背景'
      this.app.dialogParam(this.dialog.edit, ['id'], e)
      this.$refs['educations'].visible = true
    },
    handleEdit(e) {
      this.dialog.title = '编辑简历'
      this.dialog.type = 'edit'
      e.su_id = e.id
      this.app.dialogParam(this.dialog.edit, ['id', 'su_id', 'hometown', 'lived', 'marriage', 'birth', 
          'work', 'appraise', 'remark'], e)
      this.$refs['dialog'].visible = true
    },
    outData(e) {

    }
  }
}
</script>
